/**
 * 数据更新器
 * 通过更新器触发datafeeds的getBars实时更新图表数据
 */
class dataUpdater {
  constructor(datafeeds) {
    this.subscribers = {}
    this.historyProvider = datafeeds,
    this.ticker=null
  }
  subscribeBars(symbolInfo, resolution, newDataCallback, listenerGuid) {
    this.subscribers[listenerGuid] = {
      lastBarTime: null,
      listener: newDataCallback,
      resolution: resolution,
      symbolInfo: symbolInfo,
    }
    this.ticker=listenerGuid
   
  }
  unsubscribeBars(listenerGuid) {
    delete this.subscribers[listenerGuid]
  }
  updateData(barsData) {
    const _ticker=this.ticker
    const _callback=this.subscribers[_ticker]['listener'];
    if(_ticker) _callback(barsData)
 
  }
 
}

export default dataUpdater